<?php
	include('submitAdd.php');
	$dom;
?>

<article id="Domain">
	<div class="topArticle">
		<h2>Domaine</h2>
	</div>
	<div class="corpsArticle">
		<form id="domainForm" method="post" action="index.php?page=formADD">
			<label for="inputNom">Nom</label>
			<input id="inputNom" name="nomDo" type="text" />
				
			<label for="inputDesc">Description</label>
			<input id="inputDesc" name="descDo"type="text" />
			<input name="whichForm" value="domain" type="hidden" />
			<input id="sendDomainButton" type="submit">
		</form>
	</div>
</article>
<article id="Concept">
	<div class="topArticle">
		<h2>Concept</h2>
	</div>
	<div class="corpsArticle">
		<form id="conceptForm" method="post" action="index.php?page=formADD">
			<label for="selectDomain">Domaine</label>
			<select id="selectDomain" name="Domain" onchange="document.getElementById('ended').value = document.getElementById('selectDomain').value;document.getElementById('conceptForm').submit()">
			<?php
				if (isset($_SESSION['theso']))
				{
				$result = pg_query($db, "SELECT * FROM GET_DOMAINS('".$_SESSION['theso']."');");
				
				$fin = false;
				while ($data = pg_fetch_object($result)) 
				{
					if (!isset($_POST['ended']) && $fin == false)
					{
						$dom = $data->get_domains;
						$fin = true;
					}
					if(isset($_POST['ended']) && $_POST['ended'] == $data->get_domains)
					{
 					 	echo "<option selected='true' value='" . $data->get_domains ."'>".$data->get_domains."</option>";
						$dom = $data->get_domains;
					}
					else
					{
						echo "<option value='" . $data->get_domains ."'>".$data->get_domains."</option>";
					}
				}
				}
			?>
               				
      			 </select>
			<label for="inputTV">Terme Vedette</label>
			<input id="inputTV" name="termeV" type="text" />
			
      			 <br />
      			 <br />
			<table align="center">
				<tr> 
					<th><label for="selectTS">TS</label> </th>
					<th><label for="inputTG">TG</label></th>
					<th><label for="inputT">T</label></th>
				</tr>
				<tr> 
					<td> <select id="selectTS" name="TermeS">
						<?php
							if(isset($dom))
							{
								$result = pg_query($db, "SELECT * FROM GET_CONCEPTS('".$dom."');");
								if (!$result) 
								{
				  					echo "An error occured.\n";
				  					exit;
								}
								while ($data = pg_fetch_object($result)) 
								{
										echo "<option value='" . $data->get_concepts ."'>".$data->get_concepts."</option>";
								}
							}
						?>	
      					</select>
      					<input id="addTS" type="Button" name="addts" value="+" onclick="addOptionTo(document.getElementById('listTS'),document.getElementById('selectTS').value)"/>
							<input id="addTS" type="Button" name="remts" value="-" onclick="remOptionFrom(document.getElementById('listTS'),document.getElementById('listTS').value)"/>
					</td>
					<td>
					<select id="selectTG" name="TermeG">
               					<?php
							if(isset($dom))
							{
								$result = pg_query($db, "SELECT * FROM GET_CONCEPTS('".$dom."');");
								if (!$result) 
								{
				  					echo "An error occured.\n";
				  					exit;
								}
								while ($data = pg_fetch_object($result)) 
								{
										echo "<option value='" . $data->get_concepts ."'>".$data->get_concepts."</option>";
								}
							}
						?>
      					</select>
					<input id="addTG" type="Button" name="addtg" value="+" onclick="addOptionTo(document.getElementById('listTG'),document.getElementById('selectTG').value)"/>
					<input id="addTG" type="Button" name="remtg" value="-" onclick="remOptionFrom(document.getElementById('listTG'),document.getElementById('listTG').value)"/>
					</td>
					<td>
						<input id="inputT" name="Terme"type="text" />
						<input id="addT" type="Button" name="addt" value="+" onclick="addOptionTo(document.getElementById('listT'),document.getElementById('inputT').value)">
						<input id="addT" type="Button" name="remt" value="-" onclick="remOptionFrom(document.getElementById('listT'),document.getElementById('listT').value)">
					</td>
				</tr>

				<tr>
					<td>
						<select id="listTS" name="listTS[]" MULTIPLE class="listTerme">
						</select>
					</td>
					<td>
						<select id="listTG" name="listTG[]" MULTIPLE class="listTerme">
						</select>
					</td>
					<td>
								
						<select id="listT" name="listT[]" MULTIPLE class="listTerme">
						</select>
					</td>
				</tr>
			</table> 
			<input name="whichForm" value="concept" type="hidden" />
			<input id="ended" name="ended" value="no" type="hidden" />
			<br />
			<input id="sendConceptButton" type="submit" onclick="selectAll(document.getElementById('listTS')); selectAll(document.getElementById('listTG')); selectAll(document.getElementById('listT')); document.getElementById('ended').value = 'yes' ">
		</form>
		
		
				
	</div>
</article>
<article id="Association">
	<div class="topArticle">
		<h2>Association</h2>
	</div>
	<div class="corpsArticle">
		<form id="AssForm" method="post" action="index.php?page=formADD">
					
				
			<select id="selectCP1" name="CP1">
			<?php
				$qc1 = pg_query($db, "SELECT * FROM Concepts");
				if (!$qc1) 
				{
  					echo "An error occured.\n";
  					exit;
				}
				while ($c1 = pg_fetch_object($qc1)) 
				{
 					 echo "<option value=" . $c1->nom .">".$c1->nom."</option>";
				}
			?>
      			 </select>
      					 
      			 <select name="assName" class="editable-select">
               			<?php
				$qc2 = pg_query($db, "SELECT DISTINCT Nom FROM Associations ORDER BY Nom");
				if (!$qc2) 
				{
  					echo "An error occured.\n";
  					exit;
				}
				while ($c2 = pg_fetch_object($qc2)) 
				{
 					 echo "<option value=" . $c2->nom .">".$c2->nom."</option>";
				}
			?>
      			 </select>

			<select id="selectCP2" name="CP2">
               			<?php
				$qc3 = pg_query($db, "SELECT * FROM Concepts");
				if (!$qc3) 
				{
  					echo "An error occured.\n";
  					exit;
				}
				while ($c3 = pg_fetch_object($qc3)) 
				{
 					 echo "<option value=" . $c3->nom .">".$c3->nom."</option>";
				}
			?>
      			</select>
			<input type="checkbox" name="Rf" id="Rf" /> <label for="Rf">Reflexive?</label>
			<input name="whichForm" value="assoc" type="hidden" />
			<input id="sendDomainButton" type="submit">
		</form>
	</div>
</article>
